package com.xpgk.mvc.statistic.turnoverRatioStoreStatistic;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.codeSet.Code;
import com.xpgk.mvc.measurement.Temporary;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.statistic.dailyNursing.DailyNursingStatisticXLS;
import com.xpgk.mvc.user.User;
import com.xpgk.tools.ToolDateTime;

public class TurnoverRatioStoreStatisticController extends  BaseController{
	
	private  TurnoverRatioStoreStatisticService  turnoverRatioStoreStatisticService;
	
	public  void  index()
	{	
		Organization organ=Organization.dao.findById(getCUserOrganIds());
		setAttr("organization", organ);
		setAttr("startTime", ToolDateTime.getMonthOneDay(new Date()));
		render("turnoverRatioStoreStatistic.html");
	}
	
	/**获取成交率
	 * 
	 */
	public  void  getTurnoverRatioStore()
	{	
//		//将顾客类别为成交顾客的ids放入参数
//		splitPage.getQueryParam().put("gkfl", Code.cjCus_ids);
//		String json = paging(splitPage, TurnoverRatioStoreStatisticSQL.sqlId_splitPageSelect, TurnoverRatioStoreStatisticSQL.sqlId_splitPageFrom);
//		renderJson(splitPage.getList());
		String  startTime=getPara("startTime");
		String  endTime=getPara("endTime");
		String  organIds=getPara("organIds");
		List<Record> result=turnoverRatioStoreStatisticService.getTurnoverRatioStore(startTime,endTime,organIds,Code.cjCus_ids);
		renderJson(result);
	}
	/**获取未成交率占比
	 * 
	 */
	public  void  getReasonRatio()
	{	
		String  startTime=getPara("startTime");
		String  endTime=getPara("endTime");
		String date = getPara("date");
		String organIds = getPara("organIds");
		String jdrids = getPara("jdrids");
		
		List<Record> result=turnoverRatioStoreStatisticService.getReasonRatio(startTime,endTime,date,jdrids,organIds);
		renderJson(result);
	}
	
	public  void  excel()
	{
		String  startTime=getPara("startTime");
		String  endTime=getPara("endTime");
		String  organIds=getPara("organIds");
		List<Record> result=turnoverRatioStoreStatisticService.getTurnoverRatioStore(startTime,endTime,organIds,Code.cjCus_ids);
		
		
		List<Record> recordList=turnoverRatioStoreStatisticService.excel(startTime,endTime,result,organIds);
			
		//搜索条件
		Organization  organ=Organization.dao.findById(organIds);
		String  search="日期："+startTime+"~"+endTime+"，门店："+organ.getStr(Organization.column_name)+"，导出人员："+getCUser().getStr(User.column_name);
		render(new TurnoverRatioStoreStatisticXLS(recordList,search,"顾客成交率（门店）查询表"));
	}
	/**跳转到顾客成交率（门店）详情
	 * 
	 */
	public  void  tolookReasonInfo()
	{
		String date=getPara("date");
		String organIds=getPara("organIds");
		setAttr("date", date);
		setAttr("organ", Organization.dao.findById(organIds));
		render("storeStatisticInfo.html");
	}
	public  void lookReasonInfo()
	{
		String date=getPara("date");
		String organIds=getPara("organIds");
		List<Record> result=turnoverRatioStoreStatisticService.lookReasonInfo(date,organIds,Code.cjCus_ids);
		renderJson(result);
	}
}
